// Testando o commit Eduardo Gade

package Game;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.rtscup.core.Resource;

import Basic.Point;

public class Blackboard {

	private HashMap<Integer, Integer> resourcesMark;
	private HashMap<Integer, Integer> resourcesMarkFuture;

	private Map<Integer, Point> intendingTiles;

	private static Blackboard instance;

	public static Blackboard getInstance(ArrayList<Resource> resources) {
		if (instance == null) {
			instance = new Blackboard(resources);
		}

		return instance;
	}

	private Blackboard(ArrayList<Resource> resources) {
		this.resourcesMark = new HashMap<Integer, Integer>();
		this.resourcesMarkFuture = new HashMap<Integer, Integer>();

		for (Resource resource : resources) {
			this.resourcesMark.put(resource.getId(), resource.getLoad());
			this.resourcesMarkFuture.put(resource.getId(), resource.getLoad());
		}

		this.intendingTiles = new HashMap<Integer, Point>();
	}

	public void putIntending(Integer key, Point intendingPoint) {
		this.intendingTiles.put(key, intendingPoint);
	}

	public List<Point> getIntendings(Integer key) {
		List<Point> ret;

		ret = new ArrayList<Point>();
		for (Integer intendingKey : this.intendingTiles.keySet()) {
			if (!key.equals(intendingKey)) {
				ret.add(this.intendingTiles.get(intendingKey));
			}
		}

		return ret;
	}

	public HashMap<Integer, Integer> getResourcesMark() {
		return resourcesMark;
	}

	public HashMap<Integer, Integer> getResourceMarkFuture() {
		return resourcesMarkFuture;
	}

	public boolean hasAvailableMine() {
		for (int x : this.resourcesMarkFuture.values()) {
			if (x > 0)
				return true;
		}
		return false;
	}
}